package com.woniu.zhoukao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.zhoukao.entity.Address;
import com.woniu.zhoukao.mapper.AddressMapper;
import com.woniu.zhoukao.service.AddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuao
 * @since 2023-02-07 09:47:30
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    @Autowired
    AddressMapper addressMapper;

    @Override
    public void addAddress(String address, String tel, String name, Integer userId) {

        //Domain Object
        Address  addressDO = new Address();
        addressDO.setAddress(address);
        addressDO.setName(name);
        addressDO.setTel(tel);
        addressDO.setUserId(userId);

        addressMapper.insert(addressDO);

    }

    @Override
    public List<Address> allOfCurrentUser(Integer userId) {

        QueryWrapper<Address> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);

        return addressMapper.selectList(queryWrapper);
    }
}
